package com.wenan.ui.controls.listpanel
{
	import mx.collections.ArrayCollection;
	import mx.controls.DataGrid;
	
	public class DataGridSpec extends DataGrid
	{
		public function DataGridSpec()
		{
			super();
		}
		
		override public function get selectedItem():Object
		{
			var items:Array = selectedItems;
			if (items && items.length > 0)
			{
				return items[0];
			}
			return null;
		}
		
		override public function set selectedItem(item:Object):void 
		{
			selectedItems = [item];
		}
		
		override public function get selectedItems():Array 
		{
			var coll:Array = new Array();
			var s:ArrayCollection = dataProvider as ArrayCollection;
			for (var i:int=0; i<s.length; i++) {
				if (s[i]["selected"]) {
					coll.push(s[i]);
				}
			}
			return coll;
		}
		
		override public function set selectedItems(items:Array):void 
		{
			var temp:ArrayCollection = this.dataProvider as ArrayCollection;
			if (items.length > 0)
			{
				for each (var obj:Object in items)
				{
					for (var m:int=0; m<temp.length; m++)
					{
						if (obj.name == temp[m].name)
						{
							temp[m]["selected"] = true;
							break;
						}
					}
				}
				this.invalidateList();
			}
		}
		
		public function notSelectAll():void
		{ 
			var s:ArrayCollection = ArrayCollection(this.dataProvider);  
			for(var i:int=0;i<s.length;i++)
			{ 
				if(s[i]["selected"])
				{  
					s[i]["selected"] = false;
				}                 
			}         
			this.invalidateList();
		}
	}
}